package com.cskaoyan.javase.homework.senior._04io;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @description:
 * @author: 景天
 * @date: 2022/2/11 11:09
 **/

/*
利用字符流去读取一个文本文件，每次读取一行，并将这行数据逆序，写入新的文本文件当中
 */
public class Work8 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("a.txt"));
        FileWriter fileWriter = new FileWriter("b.txt");
        String line;
        // 一次读取一行
        while ((line = br.readLine()) != null) {
            StringBuilder s = new StringBuilder();
            for (int i = line.length() - 1; i >= 0; i--) {
                s.append(line.charAt(i));
            }
            fileWriter.write(s.toString());
            fileWriter.write(System.lineSeparator());
            fileWriter.flush();
        }
        br.close();
        fileWriter.close();
    }
}
